<template>
  <div class="main" :key="resize">
    <div class="left">
      <div class="top">
        <div class="top_left">
          <Map></Map>
        </div>
        <div class="top_right">
          <div>
            <Type></Type>
          </div>
          <div>
            <Model></Model>
          </div>
        </div>
      </div>
      <div class="footer">
        <div>
          <Project></Project>
        </div>
        <div>
          <Days></Days>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="top">
        <div>
          <Access :deviceData="deviceData"></Access>
        </div>
        <div>
          <onLine :deviceData="deviceData"></onLine>
        </div>
      </div>
      <div class="footer">
        <div>
          <Abnormal :deviceData="deviceData"></Abnormal>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { throttle } from 'lodash-es';
import { getAllDevice, getIsDevice } from '@/api/home';
import Access from './components/Access.vue';
import Days from './components/Days.vue';
import Map from './components/Map.vue';
import Project from './components/Project.vue';
import Abnormal from './components/abnormal.vue';
import Model from './components/model.vue';
import onLine from './components/onLine.vue';
import Type from './components/type.vue';

const deviceData = ref({});
const getData1 = async () => {
  const res = await getAllDevice();
  if (res.code == 200) {
    getData(res.data);
  }
};
const getData = async (data = {}) => {
  const res = await getIsDevice();
  if (res.code == 200) {
    deviceData.value = Object.assign(data, res.data);
  }
};
getData1();
const resize = ref(0);
onMounted(() => {
  window.addEventListener('resize', resizeDom);
});
const resizeDom = throttle(() => {
  resize.value++;
}, 500);
onUnmounted(() => {
  window.removeEventListener('resize', resizeDom);
});
</script>

<style lang="scss" scoped>
@mixin item_style {
  background-color: rgba(0, 0, 0, 0.24);
  border-radius: 0.5vh;
}
.main {
  width: 100%;
  height: 99%;
  display: flex;
  .left {
    flex: 3;
    margin-right: 1.5vh;
    display: flex;
    flex-direction: column;
    .top {
      flex: 2;
      display: flex;
      &_left {
        flex: 2;
        @include item_style;
      }
      &_right {
        flex: 1;
        margin-left: 1.5vh;
        display: flex;
        flex-direction: column;
        & > div {
          @include item_style;
          flex: 1;
          &:first-child {
            margin-bottom: 1.5vh;
          }
        }
      }
    }
    .footer {
      margin-top: 1.5vh;
      flex: 1;
      display: flex;
      justify-content: space-between;
      & > div {
        flex: 1;
        @include item_style;
        &:first-child {
          margin-right: 1.5vh;
        }
      }
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    .top {
      flex: 2;
      display: flex;
      flex-direction: column;
      & > div {
        flex: 1;
        @include item_style;
        &:first-child {
          margin-bottom: 1.5vh;
        }
      }
    }
    .footer {
      flex: 1;
      margin-top: 1.5vh;
      @include item_style;
    }
  }
}
</style>
